package com.ncst.backend.service.impl;

import com.ncst.backend.domain.InspectionRequest;
import com.ncst.backend.mapper.InspectionRequestMapper;
import com.ncst.backend.service.InspectionRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * 检验申请服务实现类
 */
@Service
public class InspectionRequestServiceImpl implements InspectionRequestService {
    
    @Autowired
    private InspectionRequestMapper inspectionRequestMapper;

    @Override
    public InspectionRequest getById(Integer id) {
        return inspectionRequestMapper.selectById(id);
    }

    @Override
    public List<InspectionRequest> getAll() {
        return inspectionRequestMapper.selectAll();
    }

    @Override
    public List<InspectionRequest> getByCondition(InspectionRequest inspectionRequest) {
        return inspectionRequestMapper.selectByCondition(inspectionRequest);
    }

    @Override
    public List<InspectionRequest> getByRegisterId(Integer registerId) {
        return inspectionRequestMapper.selectByRegisterId(registerId);
    }

    @Override
    public List<InspectionRequest> getByPage(Integer pageNum, Integer pageSize) {
        return inspectionRequestMapper.selectByPage((pageNum - 1) * pageSize, pageSize);
    }

    @Override
    public List<InspectionRequest> getByPage(Integer pageNum, Integer pageSize, InspectionRequest inspectionRequest, String startDate, String endDate) {
        return inspectionRequestMapper.selectByPageWithCondition((pageNum - 1) * pageSize, pageSize, inspectionRequest, startDate, endDate);
    }

    @Override
    public Long countAll() {
        return inspectionRequestMapper.countAll();
    }

    @Override
    public Long countByCondition(InspectionRequest inspectionRequest) {
        return inspectionRequestMapper.countByCondition(inspectionRequest);
    }

    @Override
    public boolean save(InspectionRequest inspectionRequest) {
        return inspectionRequestMapper.insert(inspectionRequest) > 0;
    }

    @Override
    public boolean saveBatch(List<InspectionRequest> list) {
        return inspectionRequestMapper.insertBatch(list) > 0;
    }

    @Override
    public boolean updateById(InspectionRequest inspectionRequest) {
        return inspectionRequestMapper.updateById(inspectionRequest) > 0;
    }

    @Override
    public boolean removeById(Integer id) {
        return inspectionRequestMapper.deleteById(id) > 0;
    }

    @Override
    public boolean removeByIds(List<Integer> ids) {
        return inspectionRequestMapper.deleteByIds(ids) > 0;
    }

    @Override
    public boolean refundById(Integer id) {
        InspectionRequest request = new InspectionRequest();
        request.setId(id);
        request.setInspectionState("已退费");
        return inspectionRequestMapper.updateById(request) > 0;
    }

    @Override
    public boolean batchRefund(List<Integer> ids) {
        for (Integer id : ids) {
            if (!refundById(id)) {
                return false;
            }
        }
        return true;
    }
}